package cn.leida.ruoyi.common.constant;

import java.util.ArrayList;
import java.util.List;

/**
 * 缓存的key 常量
 *
 * @author ruoyi
 */
public class CacheConstants {
    /**
     * 验证码有效期（分钟）
     */
    public static final Integer CAPTCHA_EXPIRATION = 2;


    private static final long day = 24 * 60 * 60;

    private static final long cacheSecond = 30 * day;

    private static final int heapSize = 1000;


    /**
     * 登录用户 redis key (25天)
     */
    public static final CacheRecord LOGIN_TOKEN_KEY = new CacheRecord("login_tokens:", heapSize, cacheSecond);

    /**
     * 验证码 redis key(2分钟)
     */
    public static final CacheRecord CAPTCHA_CODE_KEY = new CacheRecord("captcha_codes:", heapSize, CAPTCHA_EXPIRATION * 60);

    /**
     * 参数管理 cache key
     */
    public static final CacheRecord SYS_CONFIG_KEY = new CacheRecord("sys_config:", heapSize, cacheSecond);

    /**
     * 字典管理 cache key
     */
    public static final CacheRecord SYS_DICT_KEY = new CacheRecord("sys_dict:", heapSize, cacheSecond);
    /**
     * 防重提交 redis key
     */
    public static final CacheRecord REPEAT_SUBMIT_KEY = new CacheRecord("repeat_submit:", heapSize, 5);

    /**
     * 限流 redis key
     */
    public static final CacheRecord RATE_LIMIT_KEY = new CacheRecord("rate_limit:", heapSize, cacheSecond);

    /**
     * 登录账户密码错误次数 redis key
     */
    public static final CacheRecord PWD_ERR_CNT_KEY = new CacheRecord("pwd_err_cnt:", heapSize, cacheSecond);

    public static List<CacheRecord> cacheRecords() {
        List<CacheRecord> records = new ArrayList<>();
        records.add(LOGIN_TOKEN_KEY);
        records.add(CAPTCHA_CODE_KEY);
        records.add(SYS_CONFIG_KEY);
        records.add(SYS_DICT_KEY);
        records.add(REPEAT_SUBMIT_KEY);
        records.add(RATE_LIMIT_KEY);
        records.add(PWD_ERR_CNT_KEY);
        return records;
    }
}
